﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace RouteTest
{
    public class VehicleShape
    {
        public stVehicle _Vehicle = new stVehicle();
        public Label _Label=new Label();
        public Canvas _Parent;
        public bool _LockMove;

        public VehicleShape(stVehicle vehicle , Canvas parent)
        {
            _Parent = parent;

            _Vehicle = vehicle;
            _Label.Content = _Vehicle.id.ToString();
            _Label.Width = 40;
            _Label.Height = 30;
            _Label.Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));
            _Label.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
            _Label.Foreground= new SolidColorBrush(Color.FromArgb(255, 255,255, 255));
            _Label.BorderThickness = new System.Windows.Thickness(3);

            Canvas.SetLeft(_Label, _Vehicle.position.X - (_Label.Width/2));
            Canvas.SetTop(_Label, _Vehicle.position.Y - (_Label.Height / 2));

            _LockMove = false;
            _Label.MouseMove += new System.Windows.Input.MouseEventHandler(_Label_MouseMove);
        }
        
        void _Label_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (!_LockMove)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    Canvas.SetLeft(_Label, e.GetPosition(_Parent).X - (_Label.Width / 2));
                    Canvas.SetTop(_Label, e.GetPosition(_Parent).Y - (_Label.Height / 2));
                }
            }
        }
    }

    public class VehicleShapeList : List<VehicleShape>
    {
        Canvas _Parent;

        public VehicleShapeList()
        {
        }

        public VehicleShapeList(Canvas parent)
        {
            _Parent = parent;
        }

        public void AddVehicle(VehicleShape vehicle)
        {
            this.Add(vehicle);
         
            _Parent.Children.Add(this[this.Count - 1]._Label);
        }

        public void RemoveVehicle(VehicleShape vehicle)
        {
        }

        public void RemoveAtVehicle(int vehicleId)
        {
        }

        public int IsOnMouseOver()
        {
            foreach (VehicleShape vehicle in this)
            {
                if (vehicle._Label.IsMouseOver)
                    return vehicle._Vehicle.id;
            }
            return -1;
        }

        public void LockNodeMove()
        {
            for (int i = 0; i < this.Count; i++)
            {
                this[i]._LockMove = true;
            }
        }
        public void UnlockNodeMove()
        {
            for (int i = 0; i < this.Count; i++)
            {
                this[i]._LockMove = false;
            }
        }
    }
}
